@mixin border-position-radius($position: left) {
  border-top-#{$position}-radius: 0;
  border-bottom-#{$position}-radius: 0;
}
$border-change-time: 300ms;
$border-change-function: cubic-bezier(0.645, 0.045, 0.355, 1);

@mixin border-transition {
  transition: border-color $border-change-time $border-change-function;
}

.#{$devui-prefix}-form-controls input[type='text'],
.#{$devui-prefix}-form-controls input[type='password'],
[dInput] {
  width: 100%;
  height: 28px;
  font-size: $devui-font-size;

  &.#{$devui-prefix}-input-sm {
    font-size: $devui-font-size-sm;
    height: 26px;
  }

  &.#{$devui-prefix}-input-lg {
    font-size: $devui-font-size-lg;
    height: 46px;
  }
}

[dTextArea] {
  width: 100%;
}

.#{$devui-prefix}-form-controls textarea,
[dInput],
[dTextarea] {
  box-sizing: border-box;
  padding: 4px 10px;
  color: $devui-text;
  vertical-align: middle;
  border: 1px solid $devui-form-control-line;
  border-radius: $devui-border-radius;
  outline: none;
  background-color: $devui-base-bg;
  @include border-transition();

  &:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled):not(.error):not(.#{$devui-prefix}-error) {
    &:hover {
      border-color: $devui-form-control-line-hover;
    }

    &:focus {
      border-color: $devui-form-control-line-active;
    }
  }

  &[disabled],
  &.disabled,
  &.#{$devui-prefix}-disabled {
    &,
    &:hover {
      cursor: not-allowed;
      background-color: $devui-disabled-bg;
      border-color: $devui-disabled-line;
      color: $devui-disabled-text;
    }
  }
}

.#{$devui-prefix}-form-controls textarea,
[dTextarea] {
  width: 100%;
}

// input 样式
.#{$devui-prefix}-input-group {
  position: relative;
  display: table;
  border-collapse: separate;
}

.#{$devui-prefix}-input-group-addon {
  border: 1px solid $devui-form-control-line;
  border-radius: $devui-border-radius;
  display: table-cell;
  padding: 0 10px;
  text-align: center;

  &:last-child {
    @include border-position-radius(left);

    border-left: 0;
  }

  &:first-child {
    @include border-position-radius(right);

    border-right: 0;
  }
}

.#{$devui-prefix}-search-in-dropdown {
  margin: 0;
  border: none;
  padding: 5px 26px 5px 10px;
  background-color: $devui-embed-search-bg;
  color: $devui-text;

  &:-ms-input-placeholder {
    color: $devui-placeholder;
  }

  &:hover {
    background-color: $devui-embed-search-bg-hover;
  }
}

.#{$devui-prefix}-input-lg {
  font-size: $devui-font-size-page-title;
  line-height: 20px; // 同devui-input
  height: 32px;
}

.#{$devui-prefix}-input-sm {
  font-size: $devui-font-size;
  line-height: 14px; // 同devui-input
  height: 26px;
}

// dropdown 公共样式
.#{$devui-prefix}-dropup,
.#{$devui-prefix}-dropdown {
  position: relative;
}

.#{$devui-prefix}-form-group {
  position: relative;
}

.#{$devui-prefix}-form-control {
  width: 100%;
  color: $devui-text;
  background-color: $devui-base-bg;
  display: block;
  border-radius: $devui-border-radius;
  outline: 0;
  @include border-transition;

  &[disabled],
  &.disabled,
  &.#{$devui-prefix}-disabled {
    &,
    &:hover,
    &:focus {
      border-color: $devui-disabled-line;

      &,
      & > input {
        color: $devui-disabled-text;
        background-color: $devui-disabled-bg;
        cursor: not-allowed;
      }
    }
  }

  &:hover {
    border-color: $devui-form-control-line-hover;
  }

  &:focus {
    border-color: $devui-form-control-line-active;
  }
}

:not(.multiple-label-auto-complete-disabled):not(.#{$devui-prefix}-error) {
  > .#{$devui-prefix}-dropdown-origin:not(d-button):not(.icon):not([class^='icon-']):not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled) {
    &:not(.#{$devui-prefix}-dropdown-no-border):not(.#{$devui-prefix}-no-border) {
      border-color: $devui-form-control-line;
      @include border-transition;

      &:hover:not(:focus):not(.#{$devui-prefix}-dropdown-origin-open) {
        border-color: $devui-form-control-line-hover;
      }

      &:focus,
      &:focus-within {
        outline: none;
        border-color: $devui-form-control-line-active;
      }

      &.#{$devui-prefix}-dropdown-origin-open {
        outline: none;
        border-color: $devui-connected-overlay-line;
      }
    }
  }
}

.#{$devui-prefix}-dropdown-origin:not(d-button):not(.icon):not([class^='icon-']) {
  min-height: 28px;

  &:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled) {
    color: $devui-text;
  }

  & > .#{$devui-prefix}-input,
  & > .#{$devui-prefix}-form-control {
    height: 26px;
  }

  &:not(.#{$devui-prefix}-select-underlined-border):not(.#{$devui-prefix}-dropdown-no-border):not(.#{$devui-prefix}-no-border) {
    border-radius: $devui-border-radius;
    border-width: 1px;
    border-style: solid;
  }

  .#{$devui-prefix}-form-control,
  .#{$devui-prefix}-form-control:hover,
  .#{$devui-prefix}-form-control:focus,
  .#{$devui-prefix}-form-control:focus:hover,
  .#{$devui-prefix}-input-group-addon,
  .#{$devui-prefix}-input-group-addon:hover,
  .#{$devui-prefix}-input-group-addon:focus,
  > .#{$devui-prefix}-dropdown-default,
  > .#{$devui-prefix}-dropdown-default:hover,
  > .#{$devui-prefix}-dropdown-default:active,
  > .#{$devui-prefix}-dropdown-default:focus {
    border-color: transparent;
  }

  &[disabled],
  &.disabled,
  &.#{$devui-prefix}-disabled {
    .#{$devui-prefix}-form-control,
    .#{$devui-prefix}-form-control:hover,
    .#{$devui-prefix}-form-control:focus,
    .#{$devui-prefix}-form-control:focus:hover,
    .#{$devui-prefix}-input-group-addon,
    > .#{$devui-prefix}-dropdown-default,
    > .#{$devui-prefix}-dropdown-default:hover,
    > .#{$devui-prefix}-dropdown-default:active,
    > .#{$devui-prefix}-dropdown-default:focus {
      background-color: $devui-disabled-bg;
    }
  }
}

// css选择器不可合并，否则css解析器总是会失败
input::-moz-placeholder {
  color: $devui-placeholder;
}

input:-ms-input-placeholder {
  color: $devui-placeholder;
}

input::-webkit-input-placeholder {
  color: $devui-placeholder;
}

/* status style start */

/* border color and background */
[dInput]:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).error,
[dTextarea]:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).error,
[dInput]:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error,
[dTextarea]:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  border-color: $devui-danger-line;
  background-color: $devui-danger-bg;
}

[dDatePicker]:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  background-color: $devui-danger-bg;
}

d-select:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled):not(.multiple-label-auto-complete-disabled).#{$devui-prefix}-error {
  div.#{$devui-prefix}-dropdown-origin.#{$devui-prefix}-dropup,
  div.#{$devui-prefix}-dropdown-origin.#{$devui-prefix}-dropdown {
    border-color: $devui-danger-line;

    .#{$devui-prefix}-form-group .#{$devui-prefix}-input.#{$devui-prefix}-form-control.#{$devui-prefix}-select-input:not(.#{$devui-prefix}-select-search),
    .#{$devui-prefix}-form-group .#{$devui-prefix}-select-input:not(.#{$devui-prefix}-select-search) + .#{$devui-prefix}-form-control-feedback {
      background-color: $devui-danger-bg;
    }
  }
}

d-editable-select:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  .#{$devui-prefix}-form-group:not(.multiple-label-auto-complete-disabled) {
    input.#{$devui-prefix}-form-control.#{$devui-prefix}-dropdown-origin {
      border-color: $devui-danger-line;
      background-color: $devui-danger-bg; /* TODO: open时，下边框颜色 */
    }
  }
}

d-datepicker-pro:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  .#{$devui-prefix}-datepicker-pro-wrapper:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled) .#{$devui-prefix}-dropdown-toggle .#{$devui-prefix}-single-picker {
    border-color: $devui-danger-line;
    background-color: $devui-danger-bg;

    .#{$devui-prefix}-input:not(.#{$devui-prefix}-disabled) {
      background-color: $devui-danger-bg;
    }
  }
}

d-range-datepicker-pro:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  .#{$devui-prefix}-datepicker-pro-wrapper:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled) .#{$devui-prefix}-dropdown-toggle .#{$devui-prefix}-range-picker {
    border-color: $devui-danger-line;
    background-color: $devui-danger-bg;

    .#{$devui-prefix}-input:not(.#{$devui-prefix}-disabled) {
      background-color: $devui-danger-bg;
    }
  }
}

d-input-number:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  .input-box:not(:disabled) {
    border-color: $devui-danger-line;
    background-color: $devui-danger-bg;
  }
}

d-multi-auto-complete:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  :not(.multiple-label-auto-complete-disabled) {
    &.multiple-label-auto-complete.multiple-label-auto-complete-border ul.#{$devui-prefix}-dropdown-origin {
      border-color: $devui-danger-line;
      background-color: $devui-danger-bg;
    }

    input[dAutoComplete] {
      background-color: $devui-danger-bg;
    }
  }
}

d-tags-input:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  :not(.multiple-label-auto-complete-disabled) {
    div.#{$devui-prefix}-tags.#{$devui-prefix}-form-control {
      border-color: $devui-danger-line;
      background-color: $devui-danger-bg;
    }

    input.#{$devui-prefix}-input {
      background-color: $devui-danger-bg;
    }
  }
}

d-tree-select:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  :not(.multiple-label-auto-complete-disabled) {
    & > div.#{$devui-prefix}-select-input.#{$devui-prefix}-dropdown-origin.#{$devui-prefix}-tree-select-input {
      border-color: $devui-danger-line;
      background-color: $devui-danger-bg; /* TODO: open时，下边框颜色 */
    }
  }
}

d-search:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  input.#{$devui-prefix}-input {
    border-color: $devui-danger-line;
    background-color: $devui-danger-bg;
  }
}

/* border color only */
d-editor-md:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  border-color: $devui-danger-line;
}

d-editor:not([disabled]):not(.disabled):not(.#{$devui-prefix}-disabled).#{$devui-prefix}-error {
  .ql-toolbar,
  .ql-container {
    border-color: $devui-danger-line;
  }
}

d-form-control {
  d-search {
    width: 100%;
  }
}

.#{$devui-prefix}-form-controls.#{$devui-prefix}-form-control-has-suffix {
  [dInput],
  [dTextArea] {
    padding-right: 28px;
  }
}

.#{$devui-prefix}-form-controls.#{$devui-prefix}-form-control-has-suffix.#{$devui-prefix}-form-control-has-feedback {
  [dInput],
  [dTextArea] {
    padding-right: 56px;
  }
}

.#{$devui-prefix}-form-controls.#{$devui-prefix}-form-control-has-feedback {
  [dInput],
  [dTextarea] {
    padding-right: 28px;
  }

  d-search {
    .#{$devui-prefix}-search {
      .#{$devui-prefix}-search-icon {
        right: 24px;
      }

      .#{$devui-prefix}-search-line {
        right: 60px;
      }

      .#{$devui-prefix}-search-clear {
        right: 60px;
      }

      .#{$devui-prefix}-input.#{$devui-prefix}-icon-left {
        padding-right: 30px;
      }

      .#{$devui-prefix}-input {
        padding-right: 54px;
      }

      .#{$devui-prefix}-input.#{$devui-prefix}-clear-exit {
        padding-right: 84px;
      }

      .#{$devui-prefix}-search-line.#{$devui-prefix}-search-line-sm {
        right: 60px;
      }

      .#{$devui-prefix}-search-clear.#{$devui-prefix}-search-clear-sm {
        right: 60px;
      }

      .#{$devui-prefix}-input.#{$devui-prefix}-input-sm {
        padding-right: 54px;
      }

      .#{$devui-prefix}-input.#{$devui-prefix}-clear-exit.#{$devui-prefix}-input-sm {
        padding-right: 84px;
      }

      .#{$devui-prefix}-search-line.#{$devui-prefix}-search-line-lg {
        right: 70px;
      }

      .#{$devui-prefix}-search-clear.#{$devui-prefix}-search-clear-lg {
        right: 70px;
      }

      .#{$devui-prefix}-input.#{$devui-prefix}-input-lg {
        padding-right: 60px;
      }

      .#{$devui-prefix}-input.#{$devui-prefix}-clear-exit.#{$devui-prefix}-input-lg {
        padding-right: 95px;
      }
    }
  }

  d-select {
    .#{$devui-prefix}-form-group {
      .#{$devui-prefix}-select-input {
        padding-right: 48px;
      }

      .#{$devui-prefix}-form-control-feedback {
        right: 24px;
      }
    }
  }

  d-tree-select {
    vertical-align: middle;

    .#{$devui-prefix}-tree-select .#{$devui-prefix}-select-input.#{$devui-prefix}-tree-select-input {
      padding-right: 52px;
    }

    .#{$devui-prefix}-tree-select .#{$devui-prefix}-select-chevron-icon {
      right: 34px;
    }
  }

  d-input-number {
    width: 100%;

    .input-control-buttons {
      right: 32px;
    }

    .input-box {
      padding-right: 32px;
    }

    &:hover .input-box:not(.disabled) {
      padding-right: 58px;
    }
  }

  d-tags-input {
    .#{$devui-prefix}-tags {
      padding-right: 28px;
    }
  }

  d-multi-auto-complete {
    .multiple-label-auto-complete ul {
      padding-right: 28px;
    }
  }

  d-editable-select {
    .#{$devui-prefix}-form-group.#{$devui-prefix}-has-feedback > .#{$devui-prefix}-form-control-feedback {
      right: 24px;
    }

    & > div > .#{$devui-prefix}-form-control {
      padding-right: 48px;
    }
  }

  [dDatePicker].#{$devui-prefix}-form-control {
    padding-right: 32px;
  }
}

/* status style end */
